from flask import Flask,render_template,request
from datetime import datetime
app = Flask(__name__)

class Person:
    def __init__(self, name,age):
        self.name = name
        self.age = age

# 自定义过滤器
def datetime_format(value,format='%Y年%m月%d日%H时%M分%S秒'):
    return value.strftime(format)

app.add_template_filter(datetime_format,'datetime_format')
@app.route('/')
def hello_world():  # put application's code here
    return 'Hello World!321321321'

@app.route('/hello')
def heeeo():
    p = request.args.get('name',default='err',type=str)
    user =Person('ffff',3)
    d1= {
        'dd': 'ddd',
        "ll": 'lll'
    }
    dtn = datetime.now()
    return render_template('index.html',user=user,p=p,d1=d1,dtn=dtn)


# @app.route('/contronal/<int:age>')
# def contronal(age):
#     # p =request.args.get('age',default=12,type=int)
#     # return render_template('contronal.html', p=p)
#     return f'年龄为{age}'

@app.route('/contronal')
def contronal():
    # age = 71
    list = [{
        'name': '张三',
        'age': 18
    },{
        'name': '李四',
        'age': 20
    }]
    return render_template('contronal.html', list=list)


@app.route('/ext')
def ext():
    return render_template('base.html')

@app.route('/ext1')
def ext1():
    return render_template('child1.html')

@app.route('/ext2')
def ext2():
    return render_template('child2.html')

@app.route('/sta')
def sta():
    return render_template('static.html')

if __name__ == '__main__':
    app.run()
